package com.exam.controller;

import com.exam.aop.MyLog;
import com.exam.dto.ActionResult;
import com.exam.po.ExamManage;
import com.exam.po.Score;
import com.exam.po.Student;
import com.exam.service.ScoreService;
import com.exam.utils.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhanggaoxiang
 * @ClassName ScoreCpntroller 管理员成绩管理
 * @Description TODO
 * @Date 2021/1/12 15:46
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api")
public class ScoreController {
    @Autowired
     private ScoreService scoreService;
    /**
     * @Author zhanggaoxiang
     * @Description 分页查询成绩管理
     * @Date 2021/1/12 16:38
     * @Param [page, size, studentId]
     * @return com.exam.dto.ActionResult
     **/
    @GetMapping("/findstudents/{page}/{size}")
    @ResponseBody
    @MyLog(name = "find students")
    public ActionResult findScoreBySId(@PathVariable Integer page,@PathVariable Integer size){
        Map<String,Object> map=new HashMap<>();
        Integer total=scoreService.findStudentsCount();
        List<Student> list=scoreService.findScoreBySId(page,size);
        map.put("total",total);
        map.put("data",list);

        if (map!=null){
            return ApiResultHandler.buildActionResult(200,"查询成功!!",map);
        }else {
            return ApiResultHandler.buildActionResult(404,"查询失败!!",null);
        }
    }
    /**
     * @Author zhanggaoxiang
     * @Description 不分页查询
     * @Date 2021/1/12 17:19
     * @Param [studentId]
     * @return com.exam.dto.ActionResult
     **/
    @GetMapping("/findscore/{studentId}")
    @ResponseBody
    @MyLog(name = "find score")
    public ActionResult findScore(@PathVariable("studentId") Integer studentId){
        List<Score> list=scoreService.findScore(studentId);
        if (list!=null){

            return ApiResultHandler.buildActionResult(200,"查询成功!!",list);
        }else {
            return ApiResultHandler.buildActionResult(404,"查询失败!!",null);
        }
    }
    /**
     * @Author zhanggaoxiang
     * @Description 查询成绩分段分页
     * @Date 2021/1/12 17:52
     * @Param [page, size]
     * @return com.exam.dto.ActionResult
     **/
    @RequestMapping("/findexamsscore/{page}/{size}")
    @ResponseBody
    @MyLog(name = "find exams-score")
    public ActionResult findExams(@PathVariable Integer page,@PathVariable Integer size){
        Map<String,Object> map=new HashMap<>();
        Integer total=scoreService.findCount();
        List<ExamManage> list=scoreService.findExams(page,size);
        map.put("total",total);
        map.put("data",list);
        if (map!=null){

            return ApiResultHandler.buildActionResult(200,"查询成功!!",map);
        }else {
            return ApiResultHandler.buildActionResult(404,"查询失败!!",null);
        }
    }
    @GetMapping("/scores/{examcode}")
    @ResponseBody
    @MyLog(name = "find examCode-score")
    public ActionResult findByExamCode(@PathVariable Integer examcode) {
        List<Score> list = scoreService.findByExamCode(examcode);
        if (list!=null){

            return ApiResultHandler.buildActionResult(200,"查询成功!!",list);
        }else {
            return ApiResultHandler.buildActionResult(404,"查询失败!!",null);
        }
    }
}
